<!DOCTYPE html><html><head><title>Ext.util.TextMetrics | Ext JS 4.0 Documentation</title><script type="text/javascript" src="../ext-all.js"></script><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../scrollbars.css" type="text/css"><link rel="stylesheet" href="../docs.css" type="text/css"><link id="styleCss" rel="stylesheet" href="../style.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script><link rel="stylesheet" href="../prettify.css" type="text/css"><!-- link(rel: 'stylesheet', href: req.baseURL + '/css/ext4.css', type: 'text/css')--><link rel="shortcut icon" type="image/ico" href="../favicon.ico"><!--[if IE]>
<style type="text/css">.head-band { display: none; }
.header { border: 0; top: 0; left: 0px; background: url(../header.gif) repeat-x; }
.doc-tab .members .member a.more { background-color: #efefef; }
</style><link rel="stylesheet" href="/new/css/ie.css" type="text/css"><![endif]-->
</head><body id="ext-body" class="iScroll"><div id="notice" class="notice">For up to date documentation and features, visit 
<a href="http://docs.sencha.com/ext-js/4-0">http://docs.sencha.com/ext-js/4-0</a></div><div class="wrapper"><div class="head-band"></div><div class="header"><h2><a href="../index.html">Sencha Documentation</a></h2></div><div id="search"><form><input type="text" placeholder="Search" id="search-field" autocomplete="off" name="q"></form><div id="search-box"></div></div><div id="treePanel"></div><div id="container"><script type="text/javascript">

    req = {
        liveURL: '.',
        standAloneMode: true,
        origDocClass: 'Ext.util.TextMetrics',
        docClass: 'Ext.util.TextMetrics',
        docReq: 'Ext.util.TextMetrics',
        version: '4.0',
        baseURL: '.',
        baseDocURL: '.',
        baseProdURL: '.'
    };

    clsInfo = {};



</script>

<script type="text/javascript" src="../search.js"></script>
<!--script type="text/javascript" src="/new/javascripts/app/examples.js"></script-->
<script type="text/javascript" src="../class_tree.js"></script>
<script type="text/javascript" src="../class_doc.js"></script>
<script type="text/javascript">
    req.source = 'TextMetrics.html#Ext-util.TextMetrics';
    clsInfo = {"methods":["TextMetrics","bind","destroy","getHeight","getSize","getWidth","measure","setFixedWidth"],"cfgs":[],"properties":[],"events":[],"subclasses":[]};
    Ext.onReady(function() {
        Ext.create('Docs.classPanel');
    });
</script><div id="top-block" class="top-block"><h1 id="clsTitle" class="cls"><a href="../source/TextMetrics.html#Ext-util.TextMetrics" target="_blank">Ext.util.TextMetrics</a></h1></div><div id="docContent"><div id="doc-overview-content"><div class="lft"><p>
Provides precise pixel measurements for blocks of text so that you can determine exactly how high and
wide, in pixels, a given block of text will be. Note that when measuring text, it should be plain text and
should not contain any HTML, otherwise it may not be measured correctly.</p>


<p></p>

<p>The measurement works by copying the relevant CSS styles that can affect the font related display, 
then checking the size of an element that is auto-sized. Note that if the text is multi-lined, you must 
provide a <b>fixed width</b> when doing the measurement.</p>




<p>
If multiple measurements are being done on the same element, you create a new instance to initialize 
to avoid the overhead of copying the styles to the element repeatedly.
</p>

<div class="members"><div class="m-methods"><a name="methods"></a><div class="definedBy">Defined By</div><h3 class="mth p">Methods</h3><div id="method-TextMetrics" class="member f ni"><a href="Ext.util.TextMetrics.html#method-TextMetrics" rel="method-TextMetrics" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.TextMetrics.html" class="definedIn docClass">Ext.util.TextMetrics</a><br/><a href="../source/TextMetrics.html#Ext-util.TextMetrics-method-constructor" class="viewSource">view source</a></div><a name="TextMetrics"></a><a name="method-TextMetrics"></a><a href="Ext.util.TextMetrics.html#" rel="method-TextMetrics" class="cls expand">TextMetrics</a>(
<span class="pre">Mixed bindTo, Number fixedWidth</span>)
 : void</div><div class="description"><div class="short"><p>&nbsp;</p></div><div class="long">
<h3 class="pa">Parameters</h3><ul><li><span class="pre">bindTo</span> : Mixed<div class="sub-desc"><p>The element to bind to.</p>
</div></li><li><span class="pre">fixedWidth</span> : Number<div class="sub-desc"><p>A fixed width to apply to the measuring element.</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
</li></ul></div></div></div><div id="method-bind" class="member ni"><a href="Ext.util.TextMetrics.html#method-bind" rel="method-bind" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.TextMetrics.html" class="definedIn docClass">Ext.util.TextMetrics</a><br/><a href="../source/TextMetrics.html#Ext-util.TextMetrics-method-bind" class="viewSource">view source</a></div><a name="bind"></a><a name="method-bind"></a><a href="Ext.util.TextMetrics.html#" rel="method-bind" class="cls expand">bind</a>(
<span class="pre">Mixed el</span>)
 : void</div><div class="description"><div class="short"><p>Binds this TextMetrics instance to a new element</p>
</div><div class="long"><p>Binds this TextMetrics instance to a new element</p>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">el</span> : Mixed<div class="sub-desc"><p>The element</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
</li></ul></div></div></div><div id="method-destroy" class="member ni"><a href="Ext.util.TextMetrics.html#method-destroy" rel="method-destroy" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.TextMetrics.html" class="definedIn docClass">Ext.util.TextMetrics</a><br/><a href="../source/TextMetrics.html#Ext-util.TextMetrics-method-destroy" class="viewSource">view source</a></div><a name="destroy"></a><a name="method-destroy"></a><a href="Ext.util.TextMetrics.html#" rel="method-destroy" class="cls expand">destroy</a> : void</div><div class="description"><div class="short"><p>Destroy this instance</p>
</div><div class="long"><p>Destroy this instance</p>
<h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
</li></ul></div></div></div><div id="method-getHeight" class="member ni"><a href="Ext.util.TextMetrics.html#method-getHeight" rel="method-getHeight" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.TextMetrics.html" class="definedIn docClass">Ext.util.TextMetrics</a><br/><a href="../source/TextMetrics.html#Ext-util.TextMetrics-method-getHeight" class="viewSource">view source</a></div><a name="getHeight"></a><a name="method-getHeight"></a><a href="Ext.util.TextMetrics.html#" rel="method-getHeight" class="cls expand">getHeight</a>(
<span class="pre">String text</span>)
 : Number</div><div class="description"><div class="short"><p>Returns the measured height of the specified text</p>
</div><div class="long"><p>Returns the measured height of the specified text</p>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">text</span> : String<div class="sub-desc"><p>The text to measure</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Number</span>&nbsp; &nbsp;<p>height The height in pixels</p>
</li></ul></div></div></div><div id="method-getSize" class="member ni"><a href="Ext.util.TextMetrics.html#method-getSize" rel="method-getSize" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.TextMetrics.html" class="definedIn docClass">Ext.util.TextMetrics</a><br/><a href="../source/TextMetrics.html#Ext-util.TextMetrics-method-getSize" class="viewSource">view source</a></div><a name="getSize"></a><a name="method-getSize"></a><a href="Ext.util.TextMetrics.html#" rel="method-getSize" class="cls expand">getSize</a>(
<span class="pre">String text</span>)
 : Object</div><div class="description"><div class="short">Only available on the instance returned from createInstance, not on the singleton.


Returns the size of the specifie...</div><div class="long"><p><b>Only available on the instance returned from <a href="Ext.util.TextMetrics.html#createInstance" rel="Ext.util.TextMetrics#createInstance" class="docClass">createInstance</a>, <u>not</u> on the singleton.</b></p>


<p>Returns the size of the specified text based on the internal element's style and width properties</p>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">text</span> : String<div class="sub-desc"><p>The text to measure</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Object</span>&nbsp; &nbsp;<p>An object containing the text's size {width: (width), height: (height)}</p>
</li></ul></div></div></div><div id="method-getWidth" class="member ni"><a href="Ext.util.TextMetrics.html#method-getWidth" rel="method-getWidth" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.TextMetrics.html" class="definedIn docClass">Ext.util.TextMetrics</a><br/><a href="../source/TextMetrics.html#Ext-util.TextMetrics-method-getWidth" class="viewSource">view source</a></div><a name="getWidth"></a><a name="method-getWidth"></a><a href="Ext.util.TextMetrics.html#" rel="method-getWidth" class="cls expand">getWidth</a>(
<span class="pre">String text</span>)
 : Number</div><div class="description"><div class="short"><p>Returns the measured width of the specified text</p>
</div><div class="long"><p>Returns the measured width of the specified text</p>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">text</span> : String<div class="sub-desc"><p>The text to measure</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Number</span>&nbsp; &nbsp;<p>width The width in pixels</p>
</li></ul></div></div></div><div id="method-measure" class="member ni"><a href="Ext.util.TextMetrics.html#method-measure" rel="method-measure" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.TextMetrics.html" class="definedIn docClass">Ext.util.TextMetrics</a><br/><a href="../source/TextMetrics.html#Ext-util.TextMetrics-method-measure" class="viewSource">view source</a></div><a name="measure"></a><a name="method-measure"></a><a href="Ext.util.TextMetrics.html#" rel="method-measure" class="cls expand">measure</a>(
<span class="pre">String/HTMLElement el, String text, [Number fixedWidth]</span>)
 : Object</div><div class="description"><div class="short"><p>Measures the size of the specified text</p>
</div><div class="long"><p>Measures the size of the specified text</p>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">el</span> : String/HTMLElement<div class="sub-desc"><p>The element, dom node or id from which to copy existing CSS styles
that can affect the size of the rendered text</p>
</div></li><li><span class="pre">text</span> : String<div class="sub-desc"><p>The text to measure</p>
</div></li><li><span class="pre">fixedWidth</span> : Number<div class="sub-desc"><p>(optional) If the text will be multiline, you have to set a fixed width
in order to accurately measure the text height</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Object</span>&nbsp; &nbsp;<p>An object containing the text's size {width: (width), height: (height)}</p>
</li></ul></div></div></div><div id="method-setFixedWidth" class="member ni"><a href="Ext.util.TextMetrics.html#method-setFixedWidth" rel="method-setFixedWidth" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.TextMetrics.html" class="definedIn docClass">Ext.util.TextMetrics</a><br/><a href="../source/TextMetrics.html#Ext-util.TextMetrics-method-setFixedWidth" class="viewSource">view source</a></div><a name="setFixedWidth"></a><a name="method-setFixedWidth"></a><a href="Ext.util.TextMetrics.html#" rel="method-setFixedWidth" class="cls expand">setFixedWidth</a>(
<span class="pre">Number width</span>)
 : void</div><div class="description"><div class="short">Sets a fixed width on the internal measurement element.  If the text will be multiline, you have
to set a fixed width...</div><div class="long"><p>Sets a fixed width on the internal measurement element.  If the text will be multiline, you have
to set a fixed width in order to accurately measure the text height.</p>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">width</span> : Number<div class="sub-desc"><p>The width to set on the element</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
</li></ul></div></div></div></div></div></div></div><div id="pageContent"></div></div></div></div></body></html>